/**
 */
package com.dingpeikeji.quickdeer.core.modules.site.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.service.CrudService;
import com.dingpeikeji.quickdeer.core.modules.line.entity.TLine;
import com.dingpeikeji.quickdeer.core.modules.site.dao.TSitedtlDao;
import com.dingpeikeji.quickdeer.core.modules.site.entity.TSitedtl;
import com.dingpeikeji.quickdeer.core.modules.sys.entity.Area;
import com.dingpeikeji.quickdeer.core.modules.sys.service.AreaService;

import test.Pinyin4jUtil;

/**
 * 站点Service
 * @author lh
 * @version 2016-05-19
 */
@Service
@Transactional(readOnly = true)
public class TSitedtlService extends CrudService<TSitedtlDao, TSitedtl> {
	
	@Autowired
	private AreaService areaService;

	public TSitedtl get(String id) {
		return super.get(id);
	}
	
	public List<TSitedtl> findList(TSitedtl tSitedtl) {
		return super.findList(tSitedtl);
	}
	
	public List<TSitedtl> findDayRentList(TSitedtl tSitedtl) {
		return super.findList(tSitedtl);
	}
	
	
	/**
	 * 获取站点
	 * @return
	 */
	public List<TSitedtl> findTSitedtlList(TSitedtl tSitedtl) {
		return dao.findList(tSitedtl);
	}
	
	public Page<TSitedtl> findPage(Page<TSitedtl> page, TSitedtl tSitedtl) {
		return super.findPage(page, tSitedtl);
	}
	
	@Transactional(readOnly = false)
	public void save(TSitedtl tSitedtl) {
		if(tSitedtl.getSiteid() == null){
	
		//生成拼音检索码
		String tmphead = Pinyin4jUtil.getPinYin(tSitedtl.getSitename());
		tSitedtl.setQuerycode(tmphead);
		
		//为查询方便，存入国标code
		Area area = areaService.get(tSitedtl.getArea().getId());
		tSitedtl.setCitycode(area.getCode());
		
		super.save(tSitedtl);
		}else{
			super.update(tSitedtl);
		}
		
	}
	
	@Transactional(readOnly = false)
	public void delete(TSitedtl tSitedtl) {
		super.delete(tSitedtl);
	}
	
	/**
	 * 根据站点名称获取站点
	 * @param siteanme
	 * @return
	 */
	public TSitedtl getTSiteBySitename(String sitename, String spottype,String cityname) {
		return dao.getTSiteBySitename(sitename, spottype,cityname);
	}
	
	
	/**
	 * 根据spottype的值的集合获取站点
	 * @param spottypes
	 * @return
	 */
	public List<TSitedtl> getListBySpottypes(List<String> spottypes) {
		return dao.getListBySpottypes(spottypes);
	}

	public TSitedtl getDpetCity(String departCity) {//根据站点id获取站点
		return dao.getDpetCity(departCity);
	}

	public TSitedtl getDestCity(String destCity) {
		return dao.getDestCity(destCity);
	}

	public TSitedtl findDepartCity(TLine tl) {
		return dao.findDepartCity(tl);
	}

	public TSitedtl findDestCity(TLine tl) {
		return dao.findDestCity(tl);
	}

	public TSitedtl getDestCityByName(String name) {
		return dao.getDestCityByName(name);
	}

	public String getSiteIdByName(String sitename) {
		return dao.getSiteIdByName(sitename);
	}

	public List<TSitedtl> findSiteList(TSitedtl query) {
		return dao.findSiteList(query);
	}

	public String getSiteByName(String siteName) {
		return dao.getSiteByName(siteName);
	}
}
